﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASCalpuff.FileLayers
{
    public class Sort
    {
        public static List<string> MCHEM1 = new List<string>();
        public static List<string> MCHEM3 = new List<string>();
        //public static List<string> MCHEM4 = new List<string>();
        public static List<string> MCHEM41 = new List<string>();
        public static List<string> MCHEM42 = new List<string>();
        public static List<string> MCHEM43 = new List<string>();

        static Sort()
        {
            MCHEM1.Clear();
            MCHEM3.Clear();

            MCHEM41.Clear();
            MCHEM42.Clear();
            MCHEM43.Clear();

            MCHEM1.Add("SO2");
            MCHEM1.Add("SO4");
            MCHEM1.Add("NOX");
            MCHEM1.Add("HNO3");
            MCHEM1.Add("NO3");

            MCHEM3.Add("SO2");
            MCHEM3.Add("SO4");
            MCHEM3.Add("NO");
            MCHEM3.Add("NO2");
            MCHEM3.Add("HNO3");
            MCHEM3.Add("NO3");

            MCHEM41.Add("TOLUENE");
            MCHEM41.Add("XYLENE");
            MCHEM41.Add("B-PINENE");
            MCHEM41.Add("A-PINENE");
            MCHEM41.Add("SOA");

            MCHEM42.Add("B-PINEN");
            MCHEM42.Add("A-PINENE");
            MCHEM42.Add("SOA");

            MCHEM43.Add("TOLUENE");
            MCHEM43.Add("XYLENE");
            MCHEM43.Add("SOA");
        }

        /// <summary>
        /// 根据化学转化，返回正确的污染物顺序列表
        /// </summary>
        /// <returns></returns>
        public static List<string> GetPollutantRightOrder()
        {
            //List<string> right = new List<string>();
            //if (CProj.DefaultProj.BNullProj)
            //{
            //    return null;

            //}


            /////取得原有的污染物列表
            //List<string> org = new List<string>();
            //foreach (PollutionSpecies item in CProj.DefaultProj.CalPuff.PuffInp.CSpeciesList3.Ps)
            //{
            //    if (item.CalculateSpecies)
            //    {
            //        org.Add(item.Name);
            //    }

            //}



            ////根据需求排序



            //int mchem = CProj.DefaultProj.CalPuff.PuffInp.TechOption2.MCHEM;

            //if (mchem == 1)
            //{

            //    return Sort.GetRightOrder(org, Sort.MCHEM1);



            //}


            //if (mchem == 3)
            //{

            //    return Sort.GetRightOrder(org, Sort.MCHEM3);




            //}

            //if (mchem == 4)
            //{
            //    if (Sort.IsM41(org))
            //    {
            //        return Sort.GetRightOrder(org, Sort.MCHEM41);

            //    }

            //    else
            //    {
            //        if (Sort.IsM42(org))
            //        {

            //            return Sort.GetRightOrder(org, Sort.MCHEM42);
            //        }
            //        else
            //        {
            //            return Sort.GetRightOrder(org, Sort.MCHEM43);

            //        }
            //    }





            //}
            //return org;

            return null;
        }


        /// <summary>
        /// 根据固定排序，返回对应正确排序
        /// </summary>
        /// <param name="org"></param>
        /// <param name="mustOrder"></param>
        /// <returns></returns>
        protected static List<string> GetRightOrder(List<string> org, List<string> mustOrder)
        {
            List<string> right = new List<string>();

            List<string> orgClone = new List<string>();
            orgClone.AddRange(org);

            //首先加入必须选项

            foreach (string item in mustOrder)
            {
                foreach (string pollutant in org)
                {
                    if (item == pollutant)
                    {
                        right.Add(pollutant);

                        //移除对应的项目
                        orgClone.Remove(pollutant);

                        continue;

                    }


                }

            }

            //将剩余的加入其中
            foreach (string pollutant in orgClone)
            {
                right.Add(pollutant);
            }


            return right;

        }


        /// <summary>
        /// 当为第四选项时，污染物的确认
        /// </summary>
        /// <param name="ps"></param>
        /// <returns></returns>
        protected static bool IsM41(List<string> ps)
        {
            foreach (string item in Sort.MCHEM41)
            {
                bool b = ps.Contains(item);
                if (!b)
                {
                    return false;
                }

            }

            return true;

        }

        // <summary>
        /// 当不是M41，切是m42 返回true
        /// </summary>
        /// <param name="ps"></param>
        /// <returns></returns>
        protected static bool IsM42(List<string> ps)
        {
            foreach (string item in Sort.MCHEM42)
            {
                bool b = ps.Contains(item);
                if (!b)
                {
                    return false;
                }

            }

            return true;

        }

        // <summary>
        /// 
        /// </summary>
        /// <param name="ps"></param>
        /// <returns></returns>
        protected static bool IsM43(List<string> ps)
        {

            return true;

        }

    }


}
